/**
 * 
 */
package org.homeunix.thecave.plugins;

import javax.swing.JPanel;

/**
 * Implements the layout for the Export Options dialog
 * 
 * @author Santthosh
 *
 */
public class ExportPanel extends JPanel {
	
    /** Creates new form ExportDialog */
    public ExportPanel() {
        initComponents();
        buttonGroup.add(allAccounts);
        buttonGroup.add(selectedAccount);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        buttonGroup = new javax.swing.ButtonGroup();        
        chooseOption = new javax.swing.JLabel();
        allAccounts = new javax.swing.JRadioButton();
        selectedAccount = new javax.swing.JRadioButton();
        selectAccount = new javax.swing.JComboBox();
        instructions = new javax.swing.JLabel();
        destination = new javax.swing.JLabel();
        destinationPath = new javax.swing.JTextField();
        destinationBrowse = new javax.swing.JButton();
        export = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        dummy = new javax.swing.JLabel();  
        fileChooser = new javax.swing.JFileChooser();

        chooseOption.setText("Export Scope:");

        allAccounts.setMnemonic('a');
        allAccounts.setText("All Accounts");
        allAccounts.setSelected(true);
        allAccounts.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        allAccounts.setMargin(new java.awt.Insets(0, 0, 0, 0));   
        allAccounts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                    allAccountsActionPerformed(evt);
                }
        });

        selectAccount.setEnabled(false);
        
        selectedAccount.setMnemonic('s');
        selectedAccount.setText("Selected Account");
        selectedAccount.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        selectedAccount.setMargin(new java.awt.Insets(0, 0, 0, 0));
        selectedAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                    selectedAccountActionPerformed(evt);
                }
        });

        selectAccount.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No accounts" }));

        instructions.setText("Please choose the options for CSV export. You can export all accounts or individual ones.");

        destination.setText("Destination File:");        

        destinationBrowse.setMnemonic('b');
        destinationBrowse.setText("Browse");
        destinationBrowse.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinationBrowseActionPerformed(evt);
            }
        });

        export.setMnemonic('x');
        export.setText("Export");        

        cancel.setMnemonic('c');
        cancel.setText("Cancel");

        dummy.setText("  ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(instructions)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(destination)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(destinationPath))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(chooseOption)
                                        .addGap(13, 13, 13)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(selectedAccount)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(selectAccount, 0, 93, Short.MAX_VALUE))
                                            .addComponent(allAccounts))))
                                .addGap(6, 6, 6)
                                .addComponent(destinationBrowse))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(146, 146, 146)
                        .addComponent(export)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(197, Short.MAX_VALUE)
                .addComponent(dummy, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(235, 235, 235))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(instructions)
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chooseOption)
                    .addComponent(allAccounts))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(selectedAccount)
                    .addComponent(selectAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(destination)
                    .addComponent(destinationPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(destinationBrowse))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(export)
                    .addComponent(cancel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dummy, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE))
        );
    }// </editor-fold>  
    
    
    /**
     * Event handler for selection of the Browse button. Launches the file
     * chooser dialog to select the output file for exporting.
     * 
     * @param evt
     */
    private void destinationBrowseActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        int returnValue = fileChooser.showOpenDialog(this);
        
        if (returnValue == fileChooser.APPROVE_OPTION) {
               java.io.File file = fileChooser.getSelectedFile();
               destinationPath.setText(file.getAbsolutePath());                
        }
    }       
    
    /**
     * Event handler for the selected accounts radio button. Handles 
     * enabling/disabling
     * 
     * @param evt
     */
    private void selectedAccountActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        if(selectedAccount.isSelected())
        	selectAccount.setEnabled(true);
        else
        	selectAccount.setEnabled(false);
    }       
    
    /**
     * Event handler for the all accounts radio button. Handles enabling/disabling
     * 
     * @param evt
     */
    private void allAccountsActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        if(allAccounts.isSelected())
        	selectAccount.setEnabled(false);
        else
        	selectAccount.setEnabled(false);
    }       
    
    // Variables declaration - do not modify                     
    public javax.swing.JRadioButton allAccounts;
    public javax.swing.ButtonGroup buttonGroup;
    public javax.swing.JButton cancel;
    public javax.swing.JLabel chooseOption;
    public javax.swing.JLabel destination;
    public javax.swing.JButton destinationBrowse;
    public javax.swing.JTextField destinationPath;
    public javax.swing.JButton export;
    public javax.swing.JLabel instructions;
    public javax.swing.JLabel dummy;
    public javax.swing.JComboBox selectAccount;
    public javax.swing.JRadioButton selectedAccount;
    public javax.swing.JFileChooser fileChooser;
    // End of variables declaration                    
    
}
